namespace FastDevTemplate.DataAccess.Base;

public class AuditEntity<TKey> : Entity<TKey>, IAuditEntity
{
    public long CreatedAt { get; set; }
    public long LastUpdateAt { get; set; }
    public long DeleteAt { get; set; }
    public bool IsDelete { get; set; }

    public static long GetNowTimeSpan()
    {
        return DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
    }

    public void ToCreateState()
    {
        var nowDataTime = GetNowTimeSpan();
        CreatedAt = nowDataTime;
        LastUpdateAt = nowDataTime;
    }

    public void ToUpdateState()
    {
        LastUpdateAt = GetNowTimeSpan();
    }

    public void ToDeleteState()
    {
        DeleteAt = GetNowTimeSpan();
        IsDelete = true;
    }
    
    public void ToUndeleteState()
    {
        IsDelete = false;
    }
    
}

public interface IAuditEntity
{
    public void ToCreateState();

    public void ToUpdateState();
    
    public void ToDeleteState();

    public void ToUndeleteState();
}
